/*
 * AGENT SHERPA
 *  
 * Assignement 2 of the Agent Oriented Software Engineering Course
 * M.Sc. in Advanced Software Engineering (Part-time)
 * University College Dublin www.ucd.ie
 *
 * Copyright (c) 2007 Chris Walsh, Aidan Morrisy and Iain Hull.
 * All rights reserved.
 */

package org.agentsherpa;

import org.agentsherpa.model.GlobalMap;
import org.agentsherpa.model.Point;

/**
 * The LocationPerceptor provides agent beliefs, for its current location It
 * interfaces with the LocationModule to provide this data.
 */
public class LocationPerceptor extends BasePerceptor {
    /**
     * percieve the current state of the known map.
     * 
     * This is only an example of possible beliefs.
     */
    public void perceive() {
        try {
            SimulatorService simulator = getSimulator();
            Point location = simulator.getLocation(this.agent);
            adoptBelief("BELIEF(location" + location + ")");
            
            // get cell locations of possible directions
            Point north = new Point(location.getX(), location.getX()-1);
            Point south = new Point(location.getX(), location.getX()+1);
            Point east = new Point(location.getX()+1, location.getX());
            Point west = new Point(location.getX()-1, location.getX());
                  
            GlobalMap map = simulator.getMap();
           // convert cell locations to directional beliefs
            if (map.isRoad(north))
                adoptBelief("BELIEF(toThe(north,road))");
            if (map.isRoad(south))
                adoptBelief("BELIEF(toThe(south,road))");
            if (map.isRoad(east))
                adoptBelief("BELIEF(toThe(east,road))");
            if (map.isRoad(west))
                adoptBelief("BELIEF(toThe(west,road))");
        }
        catch(PerceptorException e) {
            e.printStackTrace();
        }
    }

}
